package com.example.aes;

import com.huawei.secure.android.common.encrypt.aes.AesCbc;
import com.huawei.secure.android.common.encrypt.utils.EncryptUtil;
import com.huawei.secure.android.common.encrypt.utils.HexUtil;

/**
 * Description:    类作用描述
 * Author:         WuShengqi
 * CreateDate:     2022-08-29
 * Version:        1.0
 */
public class AESUtils {
    public static String encryptCbc(byte[] contentByte, String key){
        byte[] secretKey =  HexUtil.hexStr2ByteArray(key);
        byte[] bytes= AesCbc.encrypt(contentByte, secretKey);

        return HexUtil.byteArray2HexStr(bytes);
//        return "";
    }

    public  static String decodeCbc(String content, String key){

        return new String(AesCbc.decrypt(HexUtil.hexStr2ByteArray(content), HexUtil.hexStr2ByteArray(key)));
    }

    public static String generateSecureRandom(){
        return HexUtil.byteArray2HexStr(EncryptUtil.generateSecureRandom(16));
    }
}
